<?php

//唯一标识
class UniqueUtils
{

    //获得客户访问ip，唯一的
    public static function getCurrentIP()
    {
        $ip = $_SERVER['REMOTE_ADDR'];
        return $ip;
    }

    //获取单独计算机唯一标识
    public static function getComputerSid()
    {
        // 使用 `wmic` 获取 SID
        $output = shell_exec('wmic useraccount where name="Administrator" get sid');

        if ($output) {
            // 解析结果
            $lines = explode("\n", trim($output));
            if (count($lines) > 1) {
                return trim($lines[1]); // 返回 SID 信息
            }
        }
        return null; // 获取失败
    }

    //获取不同设备标识id
    public static function getSignSid()
    {
        $userAgent =$_SERVER['HTTP_USER_AGENT'];
        return md5($userAgent);
    }

    //获取不同设备标识id
    public static function isMobile()
    {
        // 获取 User-Agent
        $userAgent = $_SERVER['HTTP_USER_AGENT'];

        // 判断是否为移动端设备
        $mobileAgents = ['Mobile', 'Android', 'iPhone', 'iPad', 'iPod', 'BlackBerry', 'Windows Phone'];
        foreach ($mobileAgents as $device) {
            if (stripos($userAgent, $device) !== false) {
                return true;
            }
        }
        return false;
    }
}

/*
 * //判断移动端还是pc端
if(isMobile()){
  // 转换为 GBK 编码
  echo "<h1  style='text-indent: 4em;'>Mobile手机移动端:".$_SERVER['REMOTE_ADDR']."</h1>";

}else{
 echo "<h1 style='text-indent: 4em;'>PC端:".$_SERVER['REMOTE_ADDR']."</h1>";
}

// 获取 SID
$sid = getComputerSid();
if ($sid) {
    echo "Computer SID: " . $sid . PHP_EOL;
} else {
    echo "Failed to retrieve SID." . PHP_EOL;
}
 */